#include <QStandardItem>
#include <QVBoxLayout>
#include <QDebug>

#include "test_kymanager_widget.h"

namespace KyOsManagerTest
{

KyManagerWidget::KyManagerWidget(PluginManager *pluginManager , QWidget *parent) : m_pluginManager(pluginManager)
{
    initWidget();
}

KyManagerWidget::~KyManagerWidget()
{
    /*  */
}

void KyManagerWidget::initWidget(void)
{
    initNavigationBar();
    initBase();

    setLayoutType(kdk::HorizontalType);

    return;
}

void KyManagerWidget::initNavigationBar(void)
{
    m_navigationBar = new kdk::KNavigationBar(this);

    QStandardItem *item1 = new QStandardItem(QIcon::fromTheme("system-computer-symbolic") , tr("测试项1"));

    m_navigationBar->addTag(tr("测试"));
    m_navigationBar->addItem(item1);

    QVBoxLayout *vLayout = new QVBoxLayout();
    vLayout->addWidget(m_navigationBar);

    sideBar()->setLayout(vLayout);

    return;
}

void KyManagerWidget::initBase(void)
{
    if (m_pluginManager == nullptr) {
        return;
    }

    QVector<KyManagerPluginProvider *> providers = m_pluginManager->getProviders();
    if (providers.size() <= 0) {
        return;
    }

    /* 用工厂创建出对象 */
    KyManagerPlugin *item = providers.at(0)->create();
    item->setGenerateReportCb(kyplugin::KyPlugin::generateReport);

    qDebug() << "item name " << item->name().c_str();

    QWidget *widget = item->createWidget();

    QVBoxLayout *vLayout = new QVBoxLayout();
    vLayout->addWidget(widget);

    baseBar()->setLayout(vLayout);

    widget->show();

    return;
}

}